<?php

namespace App\command;

use app\common\MsgType;
use App\model\Mail;
use App\model\Role;
use app\model\User;
use App\service\TradeService;
use GatewayWorker\Lib\Gateway;
use support\Constant;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;


class KickOnline extends Command
{
    protected static $defaultName = 'command:kickOnline';
    protected static $defaultDescription = 'command kickOnline';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addArgument('is_click', InputArgument::OPTIONAL, 'Name description');
        // $this->addArgument('role_id', InputArgument::OPTIONAL, 'Name description');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $is_click = $input->getArgument('is_click');
        $is_click = intval($is_click);
        // $role_id = $input->getArgument('role_id');
        // $output->writeln('Hello command:sendLotteryEmail');

        $roles = Role::query()->get()->toArray();

        $online_num = 0;
        foreach ($roles as $role) {
            $real_uuid = $role['uuid'] . '-' . $role['role_id'];
            if (Gateway::isUidOnline($real_uuid)) {
                $online_num++;

                if ($is_click) {
                    Gateway::sendToUid($real_uuid, json_encode([
                        'type' => MsgType::TYPE_34,
                    ]));
                }
            }

        }

        echo $online_num;

        return self::SUCCESS;

    }

}
